package com.googlecode.jlogalizer.mapred.util;

import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.Text;
import org.apache.log4j.Logger;

import com.googlecode.jlogalizer.mapred.log.Constants;
import com.googlecode.jlogalizer.mapred.log.map.LogMapper;

public class LogParser {
	
	private static Logger logger = Logger.getLogger(LogParser.class);
	
	private static LogParser singleton;
	
	private LogParser(){}
	
	public static LogParser getInstance() {
		if (singleton == null){
			singleton = new LogParser();
		}
		return singleton;
	}
	
	
	public String getClientIdFromLogEntry(String logFileEntry){
		logger.debug("Client Id : "+StringUtils.substringBefore(logFileEntry, Constants.HASH));
		return (StringUtils.substringBefore(logFileEntry, Constants.HASH));
		
	}
	
	public String getRawLogFromLogEntry(String logFileEntry){
		
		logger.debug("Raw Log : "+StringUtils.substringAfterLast(logFileEntry, Constants.HASH));
		return (StringUtils.substringAfterLast(logFileEntry, Constants.HASH));
		
	}

	public String getSplitMemberFromString(String key, int index){
		String[] keySplit = StringUtils.split(key, Constants.HASH);
		return keySplit[index];
	}
}
